package com.fw.service.impl;

import java.util.List;

import com.fw.dao.RoleDao;
import com.fw.dao.impl.RoleDaoImpl;
import com.fw.model.Permission;
import com.fw.model.Role;
import com.fw.service.RoleService;
import com.fw.util.RolePermissonsZtree;

public class RoleServiceImpl implements RoleService {
	RoleDao roleDao = null;
	@Override
	public boolean add_roleService(Role role) {
		roleDao = new RoleDaoImpl();
		Role r = roleDao.query_roleByRoleNameDao(role);
		if(r != null) return false;
		return roleDao.add_roleDao(role);
	}
	@Override
	public Integer query_totalRoleService(String sql) {
		roleDao = new RoleDaoImpl();
		Integer count = roleDao.query_totalRoleDao(sql);
		return count;
	}
	@Override
	public List<Role> query_allRoleByPageService(String sql, int firstPage,int maxPage) {
		roleDao = new RoleDaoImpl();
		List<Role> rs = roleDao.query_allRoleByPageDao(sql, firstPage, maxPage);
		return rs;
	}
	@Override
	public boolean delete_roleByIdService(Role role) {
		roleDao = new RoleDaoImpl();
		return roleDao.delete_roleByIdDao(role);
	}
	@Override
	public boolean update_roleByIdService(Role role) {
		roleDao = new RoleDaoImpl();
		return roleDao.update_roleByIdDao(role);
	}
	@Override
	public Role query_roleByIdService(Role role) {
		roleDao = new RoleDaoImpl();
		roleDao.query_roleByIdDao(role);
		return roleDao.query_roleByIdDao(role);
	}
	@Override
	public List<Role> query_allRoleService() {
		roleDao = new RoleDaoImpl();
		return roleDao.query_allRoleDao();
	}
	@Override
	public List<RolePermissonsZtree> query_rolePermissonsZtreeDataService(Role role) {
		roleDao = new RoleDaoImpl();
		return roleDao.query_rolePermissonsZtreeDataDao(role);
	}
	@Override
	public boolean update_rolePermissionService(Role role,List<Permission> permissions) {
		roleDao = new RoleDaoImpl();
		boolean flag = roleDao.update_rolePermissionDao(role, permissions);
		return flag;
	}
	@Override
	public List<Permission> query_permissionByRoleService(Role role) {
		return role.getPermissionsByRole();
	}

}
